﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;

using ConstructionBidOnline.DAL;
using ConstructionBidOnline.DAL.dsMeetingsInfoTableAdapters;
using ConstructionBidOnline.Common;

namespace ConstructionBidOnline.Biz
{
    /// <summary>
    /// MeetingsInfo Business Object
    /// </summary>

    public class MeetingsInfo : BOBase
    {
        #region Construction / Disposal

        /// <summary>
        /// Default constructor.
        /// </summary>
        protected MeetingsInfo() { }

        #endregion

        #region Public Properties

        #region Instance Properties


        /// <summary>
        /// MeetingID.
        /// </summary>
        public int MeetingID
        {
            get { return _meetingID; }
            set
            {
                if (_meetingID != value)
                {
                    if (OnPropertyChanging("MeetingID", _meetingID, value))
                    {
                        int oldValue = _meetingID;
                        _meetingID = value;
                        OnPropertyChanged("MeetingID", oldValue, value);
                    }
                }
            }
        }  private int _meetingID = -1;


        /// <summary>
        /// JobID_RK_tblJobs.
        /// </summary>
        public string JobID_RK_tblJobs
        {
            get { return _jobID_RK_tblJobs; }
            set
            {
                if (_jobID_RK_tblJobs != value)
                {
                    if (OnPropertyChanging("JobID_RK_tblJobs", _jobID_RK_tblJobs, value))
                    {
                        string oldValue = _jobID_RK_tblJobs;
                        _jobID_RK_tblJobs = value;
                        OnPropertyChanged("JobID_RK_tblJobs", oldValue, value);
                    }
                }
            }
        }  private string _jobID_RK_tblJobs = null;


        /// <summary>
        /// Date/time at which the Meeting was created.
        /// </summary>
        public DateTime? PostedDate
        {
            get { return _postedDate; }
            set
            {
                if (_postedDate != value)
                {
                    if (OnPropertyChanging("PostedDate", _postedDate, value))
                    {
                        DateTime? oldValue = _postedDate;
                        _postedDate = value;
                        OnPropertyChanged("PostedDate", oldValue, value);
                    }
                }
            }
        }  private DateTime? _postedDate = null;


        /// <summary>
        /// Date/time at which the Meeting was sheduled.
        /// </summary>
        public DateTime? Scheduleddate
        {
            get { return _scheduleddate; }
            set
            {
                if (_scheduleddate != value)
                {
                    if (OnPropertyChanging("Scheduleddate", _scheduleddate, value))
                    {
                        DateTime? oldValue = _scheduleddate;
                        _scheduleddate = value;
                        OnPropertyChanged("Scheduleddate", oldValue, value);
                    }
                }
            }
        }  private DateTime? _scheduleddate = null;

        /// <summary>
        /// Scheduledtime.
        /// </summary>
        public string Scheduledtime
        {
            get { return _scheduledtime; }
            set
            {
                if (_scheduledtime != value)
                {
                    if (OnPropertyChanging("Scheduledtime", _scheduledtime, value))
                    {
                        string oldValue = _scheduledtime;
                        _scheduledtime = value;
                        OnPropertyChanged("Scheduledtime", oldValue, value);
                    }
                }
            }
        }  private string _scheduledtime = null;



        /// <summary>
        /// Location.
        /// </summary>
        public string Location
        {
            get { return _location; }
            set
            {
                if (_location != value)
                {
                    if (OnPropertyChanging("Location", _location, value))
                    {
                        string oldValue = _location;
                        _location = value;
                        OnPropertyChanged("Location", oldValue, value);
                    }
                }
            }
        }  private string _location = null;


        /// <summary>
        /// Purpose.
        /// </summary>
        public string Purpose
        {
            get { return _purpose; }
            set
            {
                if (_purpose != value)
                {
                    if (OnPropertyChanging("Purpose", _purpose, value))
                    {
                        string oldValue = _purpose;
                        _purpose = value;
                        OnPropertyChanged("Purpose", oldValue, value);
                    }
                }
            }
        }  private string _purpose = null;

        #endregion

        #endregion

        #region Public Methods

        #region CreateNew

        /// <summary>
        /// Creates a new, empty MeetingsInfo object.
        /// </summary>
        public static MeetingsInfo CreateNew()
        {
            MeetingsInfo obj = new MeetingsInfo();

            // Switch state to Added prior to initializing property values.
            obj.ObjState = ObjectState.Added;

            return (obj);
        }


        [MethodImpl(MethodImplOptions.Synchronized)]
        public static MeetingsInfo CreateNew(MeetingsInfoCollection collection)
        {
            MeetingsInfo obj = CreateNew();
            collection.Add(obj);
            return (obj);
        }

        #endregion

        #region GetMeetingsInfoByID

        /// <summary>
        /// Returns a collection of MeetingsInfo.
        /// </summary>
        public static MeetingsInfo GetMeetingsInfoByID(int meetingid)
        {
            MeetingsInfoTableAdapter adapter = new MeetingsInfoTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsMeetingsInfo.MeetingsInfoDataTable tbl = adapter.GetData(meetingid);

            if (tbl.Rows.Count == 1)
            {
                MeetingsInfo MeetingsInfo = new MeetingsInfo();
                RelationalToObject(MeetingsInfo, tbl.Rows[0]);
                return (MeetingsInfo);
            }
            else if (tbl.Rows.Count > 1)
                throw new ApplicationException("Database integrity error: Specified 'meetingid' returned more than one record.");

            return (null);
        }

        #endregion

        #region GetMeetingsInfoByJobID

        /// <summary>
        /// Returns a collection of MeetingsInfo for the specified 'JobID' or null if no MeetingsInfo with the specified parameter(s) exists.
        /// </summary>
        public static MeetingsInfoCollection GetMeetingsInfoByJobID(string jobid)
        {
            MeetingsInfoTableAdapter adapter = new MeetingsInfoTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsMeetingsInfo.MeetingsInfoDataTable tbl = adapter.GetDataByJobID(jobid);

            MeetingsInfoCollection list = new MeetingsInfoCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsMeetingsInfo.MeetingsInfoRow row in tbl.Rows)
                {
                    MeetingsInfo MeetingsInfo = new MeetingsInfo();
                    RelationalToObject(MeetingsInfo, row);
                    list.Add(MeetingsInfo);
                }
            }

            return (list);
        }

        #endregion

        #region Update

        /// <summary>
        /// Updates the specified MeetingsInfo.
        /// </summary>
        public static void Update(MeetingsInfo obj)
        {
            bool updateMeetingsInfo = false;

            // Do not update invalid objects.
            if (!obj.Validate())
            {
                StringBuilder sb = new StringBuilder(2048);
                sb.Append("The object being updated has one or more invalid properties; the Update() operation for this object has been cancelled.\nError(s):");
                foreach (ValidationError err in obj.Errors)
                    sb.Append("\n* " + err.Element + ": " + err.Message);

                throw new InvalidObjectException(sb.ToString());
            }
            else
            {
                updateMeetingsInfo = (obj.ObjState != ObjectState.Unchanged);

                if (!updateMeetingsInfo)
                    return;
            }

            ObjectState originalObjectState = obj.ObjState;

            dsMeetingsInfo.MeetingsInfoDataTable tbl = null;
            if (updateMeetingsInfo)
            {
                MeetingsInfoTableAdapter adapter = new MeetingsInfoTableAdapter();
                adapter.Connection = AppSettings.GetDbConn();


                tbl = new dsMeetingsInfo.MeetingsInfoDataTable();
                dsMeetingsInfo.MeetingsInfoRow row = tbl.NewMeetingsInfoRow();
                ObjectToRelational(obj, tbl, row);

                adapter.Update(tbl);

                if (originalObjectState == ObjectState.Deleted)
                    obj = null;
                else RelationalToObject(obj, tbl.Rows[0]);
            }
        }

        #endregion

        #region Validate

        /// <summary>
        /// Validates the object based on its properties at the time of the call; updates the Errors property.
        /// </summary>
        public override bool Validate()
        {
            Errors.Clear();

            if (ObjState == ObjectState.Unchanged)
            {
                // By definition, unchanged objects are valid.
                return (true);
            }
            else if (ObjState == ObjectState.Uninitialized)
            {
                Errors.Add(new ValidationError("object", "Object is uninitialized.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else if ((ObjState == ObjectState.Deleted))
            {
                // Deleted items must have 'real' (i.e. non-negative, non-zero) key(s) to be valid.
                Errors.Add(new ValidationError("MeetingID", "Deleted object has an invalid PKID.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else  // ObjState == Added | Modified
            {

            }

            return (Errors.Count == 0);
        }

        #endregion

        #region ToString

        /// <summary>
        /// User-friendly string represetation of this object.
        /// </summary>
        public override string ToString()
        {
            return (String.Format("MeetingsInfo: MeetingID={0}, JobID={1}, {2}", MeetingID, JobID_RK_tblJobs));
        }

        #endregion

        #endregion

        #region Privates


        #endregion

    }

    /// <summary>
    /// Collection of 0 or more SubAdmin objects.
    /// </summary>

    public class MeetingsInfoCollection : List<MeetingsInfo>
    {
        #region Types

        public class UserComparer : IComparer<MeetingsInfo>
        {
            public int Compare(MeetingsInfo m1, MeetingsInfo m2)
            {
                return (String.Compare(m1.MeetingID.ToString(), m2.MeetingID.ToString()));
            }
        }

        #endregion
    }

    
    /// <summary>
    /// MeetingAcceptanceOrDecline Business Object
    /// </summary>

    public class MeetingAcceptanceOrDecline : BOBase
    {
        #region Construction / Disposal

        /// <summary>
        /// Default constructor.
        /// </summary>
        protected MeetingAcceptanceOrDecline() { }

        #endregion

        #region Public Properties

        #region Instance Properties


        /// <summary>
        /// MeetingADID.
        /// </summary>
        public int MeetingADID
        {
            get { return _meetingADID; }
            set
            {
                if (_meetingADID != value)
                {
                    if (OnPropertyChanging("MeetingADID", _meetingADID, value))
                    {
                        int oldValue = _meetingADID;
                        _meetingADID = value;
                        OnPropertyChanged("MeetingADID", oldValue, value);
                    }
                }
            }
        }  private int _meetingADID = -1;



        /// <summary>
        /// MeetingID_RK.
        /// </summary>
        public int MeetingID_RK
        {
            get { return _meetingID_RK; }
            set
            {
                if (_meetingID_RK != value)
                {
                    if (OnPropertyChanging("MeetingID_RK", _meetingID_RK, value))
                    {
                        int oldValue = _meetingID_RK;
                        _meetingID_RK = value;
                        OnPropertyChanged("MeetingID_RK", oldValue, value);
                    }
                }
            }
        }  private int _meetingID_RK = -1;


        /// <summary>
        /// UserID_RK.
        /// </summary>
        public int UserID_RK
        {
            get { return _userID_RK; }
            set
            {
                if (_userID_RK != value)
                {
                    if (OnPropertyChanging("UserID_RK", _userID_RK, value))
                    {
                        int oldValue = _userID_RK;
                        _userID_RK = value;
                        OnPropertyChanged("UserID_RK", oldValue, value);
                    }
                }
            }
        }  private int _userID_RK = -1;


        /// <summary>
        /// Status.
        /// </summary>
        public string Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    if (OnPropertyChanging("Status", _status, value))
                    {
                        string oldValue = _status;
                        _status = value;
                        OnPropertyChanged("Status", oldValue, value);
                    }
                }
            }
        }  private string _status = null;


        /// <summary>
        /// Notes.
        /// </summary>
        public string Notes
        {
            get { return _notes; }
            set
            {
                if (_notes != value)
                {
                    if (OnPropertyChanging("Notes", _notes, value))
                    {
                        string oldValue = _notes;
                        _notes = value;
                        OnPropertyChanged("Notes", oldValue, value);
                    }
                }
            }
        }  private string _notes = null;


        #endregion

        #endregion

        #region Public Methods

        #region CreateNew

        /// <summary>
        /// Creates a new, empty MeetingsInfo object.
        /// </summary>
        public static MeetingAcceptanceOrDecline CreateNew()
        {
            MeetingAcceptanceOrDecline obj = new MeetingAcceptanceOrDecline();

            // Switch state to Added prior to initializing property values.
            obj.ObjState = ObjectState.Added;

            return (obj);
        }


        [MethodImpl(MethodImplOptions.Synchronized)]
        public static MeetingAcceptanceOrDecline CreateNew(MeetingAcceptanceOrDeclineCollection collection)
        {
            MeetingAcceptanceOrDecline obj = CreateNew();
            collection.Add(obj);
            return (obj);
        }

        #endregion

        #region GetMeetingAcceptanceOrDecline

        /// <summary>
        /// Returns a collection of MeetingAcceptanceOrDecline for the specified 'Meetingid' or null if no MeetingAcceptanceOrDecline with the specified parameter(s) exists.
        /// </summary>
        public static MeetingAcceptanceOrDecline GetMeetingAcceptanceOrDecline(int meetingid, int userid, string status)
        {
            MeetingAcceptanceOrDeclineTableAdapter adapter = new MeetingAcceptanceOrDeclineTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsMeetingsInfo.MeetingAcceptanceOrDeclineDataTable tbl = adapter.GetData(meetingid, userid, status);

            if (tbl.Rows.Count == 1)
            {
                MeetingAcceptanceOrDecline meetingAcceptanceOrDecline = new MeetingAcceptanceOrDecline();
                RelationalToObject(meetingAcceptanceOrDecline, tbl.Rows[0]);
                return (meetingAcceptanceOrDecline);
            }
            else if (tbl.Rows.Count > 1)
                throw new ApplicationException("Database integrity error: Specified 'meetingid' returned more than one record.");

            return (null);
        }

        #endregion

        #region GetMeetingAcceptanceOrDeclineByStatus

        /// <summary>
        /// Returns a collection of MeetingsInfo for the specified 'fields' or null if no MeetingsInfo with the specified parameter(s) exists.
        /// </summary>
        public static MeetingAcceptanceOrDeclineCollection GetMeetingAcceptanceOrDeclineByStatus(int meetingid, string status)
        {
            MeetingAcceptanceOrDeclineTableAdapter adapter = new MeetingAcceptanceOrDeclineTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsMeetingsInfo.MeetingAcceptanceOrDeclineDataTable tbl = adapter.GetDataByStatus(meetingid,status);

            MeetingAcceptanceOrDeclineCollection list = new MeetingAcceptanceOrDeclineCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsMeetingsInfo.MeetingAcceptanceOrDeclineRow row in tbl.Rows)
                {
                    MeetingAcceptanceOrDecline meetingAcceptanceOrDecline = new MeetingAcceptanceOrDecline();
                    RelationalToObject(meetingAcceptanceOrDecline, row);
                    list.Add(meetingAcceptanceOrDecline);
                }
            }

            return (list);
        }

        #endregion

        #region Update

        /// <summary>
        /// Updates the specified MeetingsInfo.
        /// </summary>
        public static void Update(MeetingAcceptanceOrDecline obj)
        {
            bool updateMeetingAcceptanceOrDecline = false;

            // Do not update invalid objects.
            if (!obj.Validate())
            {
                StringBuilder sb = new StringBuilder(2048);
                sb.Append("The object being updated has one or more invalid properties; the Update() operation for this object has been cancelled.\nError(s):");
                foreach (ValidationError err in obj.Errors)
                    sb.Append("\n* " + err.Element + ": " + err.Message);

                throw new InvalidObjectException(sb.ToString());
            }
            else
            {
                updateMeetingAcceptanceOrDecline = (obj.ObjState != ObjectState.Unchanged);

                if (!updateMeetingAcceptanceOrDecline)
                    return;
            }

            ObjectState originalObjectState = obj.ObjState;

            dsMeetingsInfo.MeetingAcceptanceOrDeclineDataTable tbl = null;
            if (updateMeetingAcceptanceOrDecline)
            {
                MeetingAcceptanceOrDeclineTableAdapter adapter = new MeetingAcceptanceOrDeclineTableAdapter();
                adapter.Connection = AppSettings.GetDbConn();


                tbl = new dsMeetingsInfo.MeetingAcceptanceOrDeclineDataTable();
                dsMeetingsInfo.MeetingAcceptanceOrDeclineRow row = tbl.NewMeetingAcceptanceOrDeclineRow();
                ObjectToRelational(obj, tbl, row);

                adapter.Update(tbl);

                if (originalObjectState == ObjectState.Deleted)
                    obj = null;
                else RelationalToObject(obj, tbl.Rows[0]);
            }
        }

        #endregion

        #region Validate

        /// <summary>
        /// Validates the object based on its properties at the time of the call; updates the Errors property.
        /// </summary>
        public override bool Validate()
        {
            Errors.Clear();

            if (ObjState == ObjectState.Unchanged)
            {
                // By definition, unchanged objects are valid.
                return (true);
            }
            else if (ObjState == ObjectState.Uninitialized)
            {
                Errors.Add(new ValidationError("object", "Object is uninitialized.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else if ((ObjState == ObjectState.Deleted))
            {
                // Deleted items must have 'real' (i.e. non-negative, non-zero) key(s) to be valid.
                Errors.Add(new ValidationError("MeetingADID", "Deleted object has an invalid PKID.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else  // ObjState == Added | Modified
            {

            }

            return (Errors.Count == 0);
        }

        #endregion

        #region ToString

        /// <summary>
        /// User-friendly string represetation of this object.
        /// </summary>
        public override string ToString()
        {
            return (String.Format("MeetingAcceptanceOrDecline: MeetingADID={0}, status={1}, {2}", MeetingADID, Status));
        }

        #endregion

        #endregion

        #region Privates


        #endregion

    }

    /// <summary>
    /// Collection of 0 or more SubAdmin objects.
    /// </summary>

    public class MeetingAcceptanceOrDeclineCollection : List<MeetingAcceptanceOrDecline>
    {
        #region Types

        public class UserComparer : IComparer<MeetingAcceptanceOrDecline>
        {
            public int Compare(MeetingAcceptanceOrDecline m1, MeetingAcceptanceOrDecline m2)
            {
                return (String.Compare(m1.MeetingADID.ToString(), m2.MeetingADID.ToString()));
            }
        }

        #endregion
    }
}
